home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Metrowerks Versions / C07 QuickTime Movies / P02 Movie Dialog / MovieDialog.c next >
Encoding:
C/C++ Source or Header  |  1995-08-05  |  4.4 KB  |  169 lines  |  [TEXT/MMCC]

  1. //____________________________________________________________
  2. //    MovieDialog.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Gestalt.h>
  13. #include <Movies.h>   
  14.  
  15.  
  16. //____________________________________________________________
  17.  
  18. void  InitializeAllToolboxes( void );
  19. void  OpenDisplayDialog( void );
  20. void  LoadAndRunMovie( DialogPtr, Str255 );
  21.  
  22.  
  23. //____________________________________________________________
  24.  
  25. #define         rMovieWindow               128
  26. #define         rMovieDialog               128
  27. #define         kQuitButton                  1
  28. #define         kClearButton                 2
  29. #define         kApolloButton                3
  30. #define         kVenusButton                 4
  31. #define         kFrameButton                 5
  32. #define         kMovieFramePicture         128
  33. #define         kFramePixelSize              4
  34. #define         kApolloMovieName   "\p:Movie ƒ:Apollo Launch"
  35. #define         kVenusMovieName    "\p:Movie ƒ:Venus Probe"
  36.  
  37.  
  38. //____________________________________________________________
  39.  
  40. Boolean  gAllDone  = false;
  41.  
  42.  
  43. //____________________________________________________________
  44.  
  45. void  main( void )
  46. {   
  47.    InitializeAllToolboxes();
  48.  
  49.    OpenDisplayDialog();
  50. }
  51.  
  52.  
  53. //____________________________________________________________
  54.  
  55. void  OpenDisplayDialog( void )
  56. {
  57.    DialogPtr  theDialog;
  58.    short      theItem;
  59.    Boolean    allDone = false;
  60.    short      theType;    
  61.    Handle     theHandle;              
  62.    Rect       theRect;     
  63.    PicHandle  thePicture;
  64.  
  65.    theDialog = GetNewDialog( rMovieDialog, nil, (WindowPtr)-1L );
  66.    ShowWindow( theDialog );
  67.    SetPort( theDialog );
  68.    
  69.    while ( allDone == false )
  70.    {
  71.       ModalDialog( nil, &theItem );
  72.          
  73.       switch ( theItem )
  74.       {
  75.          case kApolloButton:
  76.             LoadAndRunMovie( theDialog, kApolloMovieName );
  77.             break;
  78.  
  79.          case kVenusButton:
  80.             LoadAndRunMovie( theDialog, kVenusMovieName );
  81.             break;
  82.  
  83.          case kClearButton:
  84.             GetDialogItem( theDialog, kFrameButton, &theType, &theHandle, &theRect ); 
  85.             thePicture = GetPicture( kMovieFramePicture );
  86.             DrawPicture( thePicture, &theRect );
  87.             break;
  88.             
  89.          case kQuitButton:
  90.             allDone = true;
  91.             break;
  92.       }
  93.    }
  94.    
  95.    DisposeDialog( theDialog ); 
  96. }
  97.  
  98.  
  99. //____________________________________________________________
  100.  
  101. void  LoadAndRunMovie( DialogPtr theDialog, Str255 theMovieName )
  102. {
  103.    OSErr    theError;
  104.    FSSpec   theFSSpec;
  105.    short    theFileRefNum;
  106.    Movie    theMovie;
  107.    short    theMovieResID = 0;   
  108.    Str255   theMovieResName;
  109.    Boolean  wasAltered;
  110.    Rect     theMovieBox;
  111.    short    theType;    
  112.    Handle   theHandle;              
  113.    Rect     theRect;     
  114.  
  115.    theError = FSMakeFSSpec( 0, 0L, theMovieName, &theFSSpec );
  116.    theError = OpenMovieFile( &theFSSpec, &theFileRefNum, fsRdPerm );
  117.    theError = NewMovieFromFile( &theMovie, theFileRefNum, &theMovieResID,
  118.                                  theMovieResName, newMovieActive, &wasAltered );
  119.                                          
  120.    CloseMovieFile( theFileRefNum );
  121.    
  122.    SetMovieGWorld( theMovie, (CGrafPtr)theDialog, nil); 
  123.       
  124.    GetMovieBox( theMovie, &theMovieBox );
  125.    OffsetRect( &theMovieBox, -theMovieBox.left, -theMovieBox.top );
  126.    GetDialogItem( theDialog, kFrameButton, 
  127.                   &theType, &theHandle, &theRect ); 
  128.    OffsetRect( &theMovieBox, theRect.left + kFramePixelSize, theRect.top + kFramePixelSize );
  129.    SetMovieBox( theMovie, &theMovieBox );
  130.  
  131.    GoToBeginningOfMovie( theMovie );
  132.  
  133.    StartMovie( theMovie );
  134.    
  135.    do
  136.    {
  137.       MoviesTask(theMovie, 0);
  138.    }
  139.    while ( IsMovieDone( theMovie ) == false );
  140.  
  141.    DisposeMovie( theMovie );
  142. }
  143.  
  144.  
  145. //____________________________________________________________
  146.  
  147. void  InitializeAllToolboxes( void )
  148. {
  149.    OSErr  theError;
  150.    long   theResult;
  151.  
  152.    InitGraf( &qd.thePort );
  153.    InitFonts();
  154.    InitWindows();
  155.    InitMenus();
  156.    TEInit();
  157.    InitDialogs( 0L );
  158.    FlushEvents( everyEvent, 0 );
  159.    InitCursor();
  160.  
  161.    theError = Gestalt( gestaltQuickTime, &theResult );
  162.    if ( theError != noErr )
  163.       ExitToShell();
  164.                                                  
  165.    theError = EnterMovies();  
  166.    if ( theError != noErr )
  167.       ExitToShell(); 
  168. }
  169.